#include<iostream>
#include<unordered_map>
#include<string>
using namespace std;
typedef pair<int, int> PII;
typedef pair<PII, int> PIII;
struct node
{
	int a, b, c;
};
string s;
unordered_map<string, node>mp;
unordered_map<string, int>st;
int n, m;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m;
	mp.clear();
	st.clear();
	while (n--) {
		cin >> s;
		int a, b, c;
		cin >> a >> b >> c;
		//getchar();
		//mp[s] = { {a,b},c };
		st[s] = 1;
		mp[s] = { a,b,c };
	}
	while (m--) {
		cin >> s;
		if (!st[s]) {
			cout << "-1 -1 -1" << endl;
		}
		else {
			cout << mp[s].a << " " << mp[s].b
				<<" " << mp[s].c << endl;
		}
	}
	return 0;
}